package GUI;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;

public class ViewVotesPanel extends JPanel implements ActionListener
{
	JTable votesTable;
	JButton back;
	JScrollPane tableScroll;
	boolean isAdmin;
	public ViewVotesPanel(String [] votes,boolean isAdmin)
	{
		this.isAdmin = isAdmin;
		setBounds(0,0,750,650);
		setLayout(null);
		
		Object [] [] data = new Object [votes.length] [2];
		for(int i = 0 ; i<votes.length ; ++i)
		{
			data[i][0] = votes[i].split("_")[0];
			data[i][1] = votes[i].split("_")[1];
		}
		votesTable = new JTable(data,new String [] {"Voter","Encrypted Vote"});
		votesTable . disable();
		
		tableScroll=new JScrollPane(votesTable,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
		tableScroll.setBounds(45,50,650,450);
		
		back = new JButton("Back");
		back . setBackground(Color.white);
		back . setBounds(45,500,70,30);
		back . addActionListener(this);
		
		add(back);
		add(tableScroll);
	}
	@Override
	public void actionPerformed(ActionEvent arg0) 
	{
		if(arg0.getSource() == back)
		{
			MainFrame.getMainFrame().remove(this);
			MainFrame.getMainFrame().addViewVotingPnl(isAdmin);
		}
	}
}
